-
Notifications
You must be signed in to change notification settings - Fork 506
Rework ArrayReplaceFunctionReturnTypeExtension #3958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.12.x
Are you sure you want to change the base?
Conversation
293ea40
to
2e5bfcf
Compare
This pull request has been marked as ready for review. |
I know I'm maybe a bit fast suggesting this, but we could create a |
assertType("non-empty-array<'bar'|'foo', '1'|'2'|'4'>", array_replace($array1, $array2)); | ||
assertType("array{foo: '1', bar: '2'}", array_replace($array1)); | ||
assertType("array{foo: '1', bar: '2'}", array_replace([], $array1)); | ||
assertType("array{foo: '1', bar: '4'}", array_replace($array1, $array2)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another test cases where $array2
is a general array, please? And maybe in the other section somewhere also one where $array1
is a general array but $array2
is a constant array.
a bit more mixed keys (strings or ints) would be interesting too 😊 that would also help massively with potential future refactoring
Yeah, I would prefer this to be done in a follow up PR to separate (and validate separately by ondrej)
|
5dea1cc
to
a8f870a
Compare
Close phpstan/phpstan#12828
I basically copy the ArrayMergeFunctionReturnTypeExtension with the following change
phpstan-src/src/Type/Php/ArrayMergeFunctionDynamicReturnTypeExtension.php
Line 87 in 4c41073
$keyType instanceof ConstantIntegerType ? null : $keyType,
is replaced by$keyType
becausephpstan-src/src/Type/Php/ArrayMergeFunctionDynamicReturnTypeExtension.php
Line 106 in 4c41073
if (!(new IntegerType())->isSuperTypeOf($keyType)->yes()) {
is replaced byif (!$argType->isList()->yes()) {
because of the same reason.